<?xml version="1.0"?>
<yandex>
    <!-- Profiles of settings. -->
    <profiles>
        <!-- Default settings. -->
        <default>
            <!-- Maximum memory usage for processing single query, in bytes. -->
            <max_memory_usage>{{ (ansible_memtotal_mb * 0.85 * 1024 * 1024) | int // 1 }}</max_memory_usage>
            <max_bytes_before_external_sort>{{ (ansible_memtotal_mb * 0.6 * 1024 * 1024) | int // 1 }}</max_bytes_before_external_sort>
            <max_bytes_before_external_group_by>{{ (ansible_memtotal_mb * 0.6 * 1024 * 1024) | int // 1 }}</max_bytes_before_external_group_by>
            <max_memory_usage_for_all_queries>{{ (ansible_memtotal_mb * 0.85 * 1024 * 1024) | int // 1 }}</max_memory_usage_for_all_queries>
            <max_memory_usage_for_user>{{ (ansible_memtotal_mb * 0.85 * 1024 * 1024) | int // 1 }}</max_memory_usage_for_user>
 
            <distributed_ddl_task_timeout>600</distributed_ddl_task_timeout>
            <max_threads>{{ (ansible_processor_vcpus * 0.9) | int // 1  }}</max_threads>
            <max_insert_threads>{{ (ansible_processor_vcpus * 0.5) | int // 1  }}</max_insert_threads>
            <max_alter_threads>{{ (ansible_processor_vcpus * 0.9) | int // 1  }}</max_alter_threads>
            <max_partitions_per_insert_block>1000</max_partitions_per_insert_block>
            <background_pool_size>136</background_pool_size>
            <background_schedule_pool_size>136</background_schedule_pool_size>
            <background_distributed_schedule_pool_size>136</background_distributed_schedule_pool_size>
            <send_timeout>30000</send_timeout>
            <receive_timeout>30000</receive_timeout>

            <!-- Use cache of uncompressed blocks of data. Meaningful only for processing many of very short queries. -->
            <use_uncompressed_cache>0</use_uncompressed_cache>
            <load_balancing>random</load_balancing>
        </default>

        <!-- Profile that allows only read queries. -->
        <readonly>
            <readonly>1</readonly>
        </readonly>
    </profiles>

    <!-- Users and ACL. -->
    <users>
        <!-- If user name was not specified, 'default' user is used. -->
        <default>
 
            <password>{{ ck_password }}</password>

            <networks incl="networks" replace="replace">
                <ip>::/0</ip>
            </networks>
            <access_management>1</access_management>
            <!-- Settings profile for user. -->
            <profile>default</profile>

            <!-- Quota for user. -->
            <quota>default</quota>
        </default>
    </users>

    <!-- Quotas. -->
    <quotas>
        <!-- Name of quota. -->
        <default>
            <!-- Limits for time interval. You could specify many intervals with different limits. -->
            <interval>
                <!-- Length of interval. -->
                <duration>3600</duration>

                <!-- No limits. Just calculate resource usage for time interval. -->
                <queries>0</queries>
                <errors>0</errors>
                <result_rows>0</result_rows>
                <read_rows>0</read_rows>
                <execution_time>0</execution_time>
            </interval>
        </default>
    </quotas>
</yandex>
